package Noyau;

import java.util.List;
import java.util.ArrayList;
import java.util.Observer;
import java.util.Random;

public class Aeroport 
{
    private List<Chemin> chemins = new ArrayList<Chemin> ();
    private boolean modeManuel = false;

    public List<Chemin> getChemins ()  {
        return this.chemins;
    }
    
    public void addChemin(Chemin value)
    {
    	this.chemins.add(value);
    	value.setAeroport(this);
    }
    
    public boolean isModeManuel()
    {
    	return this.modeManuel;
    }
    
    public void setModeManuel(boolean value)
    {
    	this.modeManuel = value;
    }
    
    public void updateAll()
    {
    	for (Chemin chemin : this.chemins) 
    	{
			chemin.updateVisual();
		}
    }
   
    public void setObserver(Observer observer)
    {
    	for (Chemin chemin : this.chemins)
    	{
    		chemin.addObserver(observer);
    	}
    }
    
    public void reset()
    {
    	this.chemins.clear();
    	this.modeManuel = false;
    }
    
    public Toboggan getRandomToboggan()
    {
    	List<Toboggan> toboggans = new ArrayList<Toboggan>();
    	
    	for (Chemin chemin : this.chemins) {
			if (chemin instanceof Toboggan)
			{
				toboggans.add((Toboggan)chemin);
			}
		}
    	
    	if (toboggans.size() == 0)
    	{
    		return null;
    	}
    	
    	Random rdm = new Random();
    	int tobogganIndex = rdm.nextInt(toboggans.size());
    	
    	return toboggans.get(tobogganIndex);
    }
}
